package httpServer

import (
	"net/http"

	log "github.com/cihub/seelog"
)

var (
	server *HttpServer
)

type HttpServer struct {
	name string
	addr string
}

func CreateHttpServer(name string, addr string) *HttpServer {
	server = &HttpServer{
		name: name,
		addr: addr,
	}
	return server
}

func (httpServer *HttpServer) Start() error {
	err := http.ListenAndServe(server.addr, nil)
	if err != nil {
		log.Error("HttpServer " + server.name + "failed Listening on " + server.addr)
	}
	return err
}

func (httpServer *HttpServer) AddRouter(pattern string, handle func(w http.ResponseWriter, r *http.Request)) {
	http.HandleFunc(pattern, handle)
}
